package com.szrt.javaweb.oa.employee.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.szrt.javaweb.oa.common.MessageDTO;
import com.szrt.javaweb.oa.employee.dao.EmployeeDao;
import com.szrt.javaweb.oa.employee.entity.EmployeeEntity;

@Service
public class EmployeeService {
	
	@Autowired
	private EmployeeDao dao;
	
	public void loginCheck(EmployeeEntity entity,Map<String,Object> map){
		try{
			int counter = dao.loginCheck(entity);
			
			if(counter ==1){
				MessageDTO.putSuccessMessage(map);
			}else{
				MessageDTO.putFailureMessage(map);
			}
		}catch(Exception e){
			MessageDTO.putErrorMessage(map);
			e.printStackTrace();
		}
	}

	public void findAll(Map<String,Object> map) {
		try{
			List<EmployeeEntity> list = dao.findAll();
			
			map.put("rows", list);
			MessageDTO.putSuccessMessage(map);
		}catch(Exception e){
			MessageDTO.putErrorMessage(map);
			e.printStackTrace();
		}
		
	}

	public void findAllPage(Map<String, Integer> fenye, Map<String, Object> reuslt) {
		try{
			List<EmployeeEntity> rows = dao.findAllPage(fenye);
			
			int total =dao.counterEmployee();
			
			//EasyUI 规定最少要2个数据给到前台  
			//1:告诉前台一共有多少条数据total
			//2:我这一页有多少条记录 rows
			reuslt.put("rows", rows);
			reuslt.put("total", total);
			MessageDTO.putSuccessMessage(reuslt);
		}catch(Exception e){
			MessageDTO.putErrorMessage(reuslt);
			e.printStackTrace();
		}
		
	}
}
